

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gczn_hd/app/core/values/app_colors.dart';

class GcznPage extends StatelessWidget{

  final Widget child;
  final Function()? onLoadNextPage;
  final Future<void> Function()? onRefresh;

   final Color? textColor;

  EasyRefreshController? easyController;
  ScrollController? scrollController;

  GcznPage({
    Key? key,
    required this.child,
    this.onLoadNextPage,
    this.onRefresh,
    this.easyController,
    this.scrollController,
    this.textColor = AppColors.colorWhite,
}) : super(key:key){

    easyController ??= EasyRefreshController(
      controlFinishRefresh: true,
      controlFinishLoad: true,
    );

  }



  @override
  Widget build(BuildContext context) {

    return EasyRefresh(
      controller: easyController,
      refreshOnStart: false,   // 打开就是刷新状态
      scrollController: scrollController??ScrollController(),
      header:  ClassicHeader(
        hitOver: true,
        safeArea: false,
        processedDuration: Duration.zero,
        showMessage: true,
        showText: true,
        textStyle: TextStyle(color: textColor),
        messageStyle: TextStyle(color: textColor),
        iconTheme: IconThemeData(color: textColor),
        messageText: "最近更新 %T",
        processedText: "刷新成功",
        processingText: "正在刷新...",
        readyText: "正在刷新...",
        armedText: "释放以刷新",
        dragText: "下拉刷新",
        failedText: "刷新失败"
      ),
      footer: ClassicFooter(
          processedDuration: Duration.zero,
          textStyle: TextStyle(color: textColor),
          messageStyle: TextStyle(color: textColor),
          iconTheme: IconThemeData(color:  textColor),
          showText: true,
          showMessage: false,
          processedText: "加载成功",
          processingText: "加载中...",
          readyText: "正在加载...",
          armedText: "释放以加载更多",
          dragText: "上拉加载",
          failedText: "加载失败",
          noMoreText: "没有更多数据",
          noMoreIcon: Icon(Icons.info),

      ),
      onRefresh: () async {
        await onRefresh!();
        easyController!.finishRefresh();
        // easyController!.resetFooter();
      },
      onLoad: onLoadNextPage != null ? () async {
        await onLoadNextPage!();
      }: null,
      child: child,
    );
  }
}